Skip to content

fix(agents): preserve format guard recovery - #2985

Merged
stranske merged 9 commits into
mainfrom
agent/sync-format-guard-source-fix
Aug 8, 2026
Merged

fix(agents): preserve format guard recovery#2985
stranske merged 9 commits into
mainfrom
agent/sync-format-guard-source-fix

Conversation

@stranske

@stranske stranske commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Fixes source-owned findings from the current sync wave.

  • release the format lease when explicit optimizer dispatch fails
  • keep issue-dedup advisory under bash -e
  • preserve info-level logging severity
  • mirror consumer workflow templates

Validation:

  • python -m pytest -q tests/scripts/test_issue_format.py tests/workflows/test_agents_issue_optimizer_format_trigger.py
  • node --test .github/scripts/tests/github-api-with-retry.test.js
  • git diff --check

Summary by CodeRabbit

  • Bug Fixes

    • Improved workflow recovery when dispatches fail by distinguishing accepted requests and preserving temporary formatting locks when status is uncertain.
    • Advisory deduplication failures now generate warnings without stopping subsequent processing.
    • Corrected informational logging so non-error messages use standard output.
  • Tests

    • Added coverage for dispatch timestamps, lock handling, warning behavior, label cleanup, and completion markers during workflow failures.
  • Chores

    • Updated workflow consistency baselines and worker attempt metadata.

Copilot AI lite review requested due to automatic review settings August 8, 2026 15:33
@cursor

cursor Bot commented Aug 8, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 39 minutes

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6108d844-cc08-4421-af76-32296d15cfc0

📥 Commits

Reviewing files that changed from the base of the PR and between c8482fc and 888481b.

📒 Files selected for processing (1)
  • tests/workflows/test_agents_issue_optimizer_format_trigger.py
📝 Walkthrough

Walkthrough

The change updates mirrored logging scripts and workflow templates. Optimizer workflows capture deduplication failures. Format guard workflows distinguish accepted dispatches from failed requests and manage the agents:format lease. Tests cover the failure path.

Changes

Workflow reliability updates

Layer / File(s) Summary
Fallback logging behavior
.github/scripts/github-api-with-retry.js, templates/consumer-repo/.github/scripts/github-api-with-retry.js
Non-error and non-warning messages now use console.log.
Deduplication error handling
.github/workflows/agents-issue-optimizer.yml, templates/consumer-repo/.github/workflows/agents-issue-optimizer.yml, config/template-drift-allowlist.txt
The workflows capture deduplication status without immediate shell termination, restore shell error handling, and update the corresponding drift fingerprints and rationale.
Format-lease dispatch handling and validation
.github/workflows/agents-issue-format-guard.yml, templates/consumer-repo/.github/workflows/agents-issue-format-guard.yml, tests/workflows/test_agents_issue_optimizer_format_trigger.py
The workflows record dispatch time and check for accepted runs after CLI failure. Ambiguous dispatches preserve the agents:format lease without writing a completion marker. Confirmed failures release the lease. Tests validate the failure behavior.
Worker attempt metadata
langsmith-fleet-worker-attempt.json
The emission timestamp and PR number are updated while the execution settings remain unchanged.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant FormatGuard
  participant GitHubActions
  participant IssueLabels
  FormatGuard->>GitHubActions: Dispatch optimizer workflow
  GitHubActions-->>FormatGuard: Return CLI failure
  FormatGuard->>GitHubActions: Query matching runs after dispatch time
  GitHubActions-->>FormatGuard: Report accepted run or no matching run
  FormatGuard->>IssueLabels: Preserve or remove agents:format lease
Loading

Possibly related PRs

Suggested labels: verify:compare

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the agents change to preserve format guard recovery, which is a primary objective of the pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/sync-format-guard-source-fix

Comment @coderabbitai help to get the list of available commands.

@stranske
stranske temporarily deployed to agent-high-privilege August 8, 2026 15:33 — with GitHub Actions Inactive
@agents-workflows-bot

agents-workflows-bot Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Workflow source detected

PR #2985 now has valid workflow source context (origin=sync_campaign).

No linked GitHub issue is required for this PR.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the agents issue-format “lease”/handoff flow and logging so failed dispatches remain retryable, advisory dedup does not break the job under bash -e, and info-level logs don’t get emitted as errors—while keeping consumer templates mirrored with the source workflows.

Changes:

  • Release the agents:format label lease when the format-guard cannot dispatch the optimizer, so later guard runs can retry.
  • Run the advisory issue-dedup Python block with errexit temporarily disabled, capturing its exit code and restoring -e afterward.
  • Fix logWithCore fallback logging so non-warning/non-error levels use console.log, and mirror all workflow/script changes into templates/consumer-repo/.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/workflows/test_agents_issue_optimizer_format_trigger.py Extends assertions to ensure the format lease is explicitly released on dispatch failure before emitting the retryable error marker.
.github/workflows/agents-issue-format-guard.yml Removes agents:format label on optimizer dispatch failure to avoid leaving a stuck lease.
templates/consumer-repo/.github/workflows/agents-issue-format-guard.yml Mirrors the same lease-release-on-dispatch-failure behavior for consumer templates.
.github/workflows/agents-issue-optimizer.yml Wraps advisory dedup Python execution with set +e/set -e so failures become warnings instead of aborting the step.
templates/consumer-repo/.github/workflows/agents-issue-optimizer.yml Mirrors the same advisory dedup error-handling behavior for consumer templates.
.github/scripts/github-api-with-retry.js Preserves info-level severity by using console.log (not console.error) for non-warning/non-error fallback logging.
templates/consumer-repo/.github/scripts/github-api-with-retry.js Mirrors the logging fallback severity fix for consumer templates.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@stranske stranske added the autofix Opt-in automated formatting & lint remediation label Aug 8, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In @.github/workflows/agents-issue-format-guard.yml:
- Around line 207-208: Update the dispatch failure handling in both
.github/workflows/agents-issue-format-guard.yml (lines 207-208) and
templates/consumer-repo/.github/workflows/agents-issue-format-guard.yml (lines
207-208): reconcile the failed gh workflow run dispatch using run details or a
unique marker, and remove the agents:format lease only when no accepted dispatch
is found; otherwise preserve the lease to prevent duplicate runs.

In `@tests/workflows/test_agents_issue_optimizer_format_trigger.py`:
- Around line 84-87: Strengthen the assertions in the test around the generated
workflow trigger text so they match the complete failure-handling block,
including the `if ! gh workflow run ...; then` condition, the `--remove-label
"agents:format"` cleanup, and the retry warning message. Assert the warning
branch structure and ordering together, rather than only comparing independent
positions, so unconditional or success-path label removal cannot satisfy the
test.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 490e3ac7-6f02-4936-b0c3-acf25943a1eb

📥 Commits

Reviewing files that changed from the base of the PR and between 25fcff7 and 38ad654.

📒 Files selected for processing (7)
  • .github/scripts/github-api-with-retry.js
  • .github/workflows/agents-issue-format-guard.yml
  • .github/workflows/agents-issue-optimizer.yml
  • templates/consumer-repo/.github/scripts/github-api-with-retry.js
  • templates/consumer-repo/.github/workflows/agents-issue-format-guard.yml
  • templates/consumer-repo/.github/workflows/agents-issue-optimizer.yml
  • tests/workflows/test_agents_issue_optimizer_format_trigger.py

Comment thread .github/workflows/agents-issue-format-guard.yml
Comment thread tests/workflows/test_agents_issue_optimizer_format_trigger.py Outdated
@stranske stranske added agents:keepalive Use to initiate keepalive functionality with agents agent:codex Agent-created issues from Codex labels Aug 8, 2026
@stranske-keepalive

stranske-keepalive Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

🤖 Keepalive Loop Status

PR #2985 | Agent: Codex | Iteration 0/12

Current State

Metric Value
Iteration progress [----------] 0/12
Action skip (needs-human)
Disposition skipped
Gate success
Tasks 0/7 complete
Timeout 45 min (default)
Timeout usage 9m elapsed (22%, 36m remaining)
Keepalive ✅ enabled
Autofix ❌ disabled

🔍 Failure Classification

| Error type | infrastructure |
| Error category | unknown |
| Suggested recovery | Capture logs and context; retry once and escalate if the issue persists. |

⚠️ Failure Tracking

| Consecutive failures | 3/3 |
| Reason | agent-run-failed |

@stranske-keepalive

stranske-keepalive Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor
Keepalive Work Log (click to expand)
# Time (UTC) Agent Action Result Files Tasks Progress Commit Gate
0 2026-08-08 15:38:05 Codex wait (gate-cancelled-transient-transient) skipped 0 0/7 cancelled
0 2026-08-08 15:38:41 Codex wait (gate-cancelled-transient-transient) skipped 0 0/7 cancelled
0 2026-08-08 15:41:07 Codex run (agent-run-failed) failure 2 file(s) 0 0/7 ea89004 cancelled
0 2026-08-08 15:41:48 Codex wait (gate-cancelled-transient-transient) skipped 0 0/7 cancelled
0 2026-08-08 15:44:44 Codex run (agent-run-failed) failure 2 file(s) 0 0/7 7e00ff4 cancelled
0 2026-08-08 15:48:18 Codex run (agent-run-failed) failure 2 file(s) 0 0/7 7682c64 cancelled
0 2026-08-08 15:51:51 Codex run (agent-run-failed-repeat) failure 2 file(s) 0 0/7 c8482fc cancelled
0 2026-08-08 15:52:38 Codex skip (needs-human) skipped 0 0/7
0 2026-08-08 15:53:25 Codex skip (needs-human) skipped 0 0/7 cancelled
0 2026-08-08 16:01:06 Codex skip (needs-human) skipped 0 0/7 failure
0 2026-08-08 16:06:21 Codex skip (needs-human) skipped 0 0/7 success
0 2026-08-09 04:39:11 Codex skip (needs-human) skipped 0 0/7
0 2026-08-09 04:48:31 Codex skip (needs-human) skipped 0 0/7 success

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Runner dispatch state for codex on PR #2985. Do not edit.

@github-actions
github-actions Bot temporarily deployed to agent-high-privilege August 8, 2026 15:38 Inactive
codex-automation and others added 2 commits August 8, 2026 10:39
Preserve agents:format when gh workflow run errors after GitHub accepts
the optimizer dispatch; release only when no matching run appears.

Co-authored-by: Cursor <cursoragent@cursor.com>
Refresh pair.11 hashes after the shared bash -e advisory dedup wrap so
Health 74 stops treating intentional root/consumer divergence as drift.

Co-authored-by: Cursor <cursoragent@cursor.com>
@stranske
stranske temporarily deployed to agent-high-privilege August 8, 2026 15:42 — with GitHub Actions Inactive
@agents-workflows-bot
agents-workflows-bot Bot temporarily deployed to agent-high-privilege August 8, 2026 15:45 Inactive
@agents-workflows-bot
agents-workflows-bot Bot temporarily deployed to agent-high-privilege August 8, 2026 15:49 Inactive
@agents-workflows-bot agents-workflows-bot Bot added the agent:needs-attention Agent needs human review or intervention label Aug 8, 2026
@agents-workflows-bot agents-workflows-bot Bot added the needs-human Requires human intervention or review label Aug 8, 2026
@agents-workflows-bot
agents-workflows-bot Bot temporarily deployed to agent-high-privilege August 8, 2026 15:52 Inactive
@stranske

stranske commented Aug 8, 2026

Copy link
Copy Markdown
Owner Author

Runner dispatch state for autofix on PR #2985. Do not edit.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Autofix updated these files:

  • tests/workflows/test_agents_issue_optimizer_format_trigger.py

@agents-workflows-bot
agents-workflows-bot Bot temporarily deployed to agent-high-privilege August 8, 2026 16:01 Inactive
@agents-workflows-bot

Copy link
Copy Markdown
Contributor

🤖 Bot Comment Handler

  • Agent: codex
  • Bot comments to address: 2

The agent has been assigned to this PR to address the bot review comments.

Instructions for agent

  1. Implement suggested fixes that improve the code
  2. Skip suggestions that don't apply (note why in your response)

The bot comment handler workflow has prepared context in the artifacts.

@stranske
stranske merged commit d4478ef into main Aug 8, 2026
53 checks passed
@stranske
stranske deleted the agent/sync-format-guard-source-fix branch August 8, 2026 16:17
@stranske stranske added the verify:compare Compare multiple LLM evaluations label Aug 9, 2026
@stranske
stranske temporarily deployed to agent-high-privilege August 9, 2026 04:38 — with GitHub Actions Inactive
@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Provider Comparison Report

Provider Summary

Provider Model Verdict Confidence Summary
openai gpt-5.6-terra CONCERNS 84% The PR implements all stated change areas: confirmed failed optimizer dispatches remove the format lease, accepted-but-CLI-failed dispatches preserve it, issue-dedup is made advisory despite bash -...
anthropic claude-sonnet-5 PASS 72% The PR addresses all four stated tasks: (1) release of the agents:format lease on genuine optimizer dispatch failure is implemented via a retry-based ambiguity check that avoids releasing the lease...
📋 Full Provider Details (click to expand)

openai

  • Model: gpt-5.6-terra
  • Verdict: CONCERNS
  • Confidence: 84%
  • Scores:
    • Correctness: 8.0/10
    • Completeness: 8.0/10
    • Quality: 8.0/10
    • Testing: 7.0/10
    • Risks: 7.0/10
  • Summary: The PR implements all stated change areas: confirmed failed optimizer dispatches remove the format lease, accepted-but-CLI-failed dispatches preserve it, issue-dedup is made advisory despite bash -e, info logging correctly falls back to console.log, and the corresponding consumer templates are mirrored. The dedup shell handling is correct and the implementation is readable. However, the new run-list verification itself is not failure-tolerant under bash -e, so a lookup failure can bypass lease cleanup. The added workflow test coverage appears focused on source-level trigger behavior and does not demonstrate this polling/error-path recovery behavior.
  • Concerns:
    • The new dispatch-acceptance polling path is executed under bash -e without guarding gh run list | jq. A transient GitHub CLI/API failure or jq failure during any poll exits the step immediately, before the failed agents:format lease is removed. This leaves the issue unable to retry, which is the recovery condition this change is intended to address.
    • Acceptance detection uses a timestamp with second-level precision plus a display-title substring match. An unrelated or prior matching run created within the same second could be treated as confirmation that the failed dispatch was accepted, preserving the lease unnecessarily. This is a relatively low-probability false-positive but affects recovery behavior.

anthropic

  • Model: claude-sonnet-5
  • Verdict: PASS
  • Confidence: 72%
  • Scores:
    • Correctness: 8.0/10
    • Completeness: 8.0/10
    • Quality: 7.0/10
    • Testing: 6.0/10
    • Risks: 7.0/10
  • Summary: The PR addresses all four stated tasks: (1) release of the agents:format lease on genuine optimizer dispatch failure is implemented via a retry-based ambiguity check that avoids releasing the lease if the dispatch actually succeeded despite a non-zero CLI exit — this is a reasonable and correct approach; (2) issue-dedup advisory handling under bash -e is fixed by wrapping the python block with set +e/set -e, ensuring the dedup return code is captured instead of aborting the script; (3) info-level logging severity is preserved by routing non-error/non-warning levels to console.log instead of console.error; (4) consumer workflow templates were mirrored with matching changes and the template-drift-allowlist hashes were updated accordingly. Code quality is reasonable, though the new polling/ambiguity-detection logic in the format guard workflow is fairly intricate and could benefit from clearer inline documentation or dedicated tests. Test coverage additions are minimal (only +10 lines in one test file visible), so full acceptance-criteria command execution can't be independently confirmed from the diff, but per-guideline testing gaps alone don't block a PASS given the implementation appears functionally correct and CI signals (Python/JS tests, lint, format) for the merge commit are green. No major security or breaking-change risks identified.
  • Concerns:
    • The retry/polling logic for detecting an 'ambiguous' dispatch (gh workflow run CLI failure but run actually accepted) adds complexity (5 retries x 2s sleep, jq-based JSON matching on createdAt/displayTitle) that is harder to verify deterministically in tests; correctness relies on GitHub API timing assumptions (string-based ISO8601 comparison, title matching '#NUMBER').
    • The diff for tests/workflows/test_agents_issue_optimizer_format_trigger.py only shows +10 lines with no visibility into what new scenario is covered (e.g., dispatch-failure-then-lease-release path is not obviously exercised based on the truncated diff).
    • No new/updated test asserting the info-level logging fix (console.log vs console.error) is visible in the diff for github-api-with-retry.test.js, though existing CI (JavaScript Tests) reportedly passed.
    • Manual verification of git diff --check and the two pytest/node test commands listed in acceptance criteria isn't directly confirmable from the diff alone, though CI summary indicates related test suites passed.

Agreement

  • Correctness: scores within 1 point (avg 8.0/10, range 8.0-8.0)
  • Completeness: scores within 1 point (avg 8.0/10, range 8.0-8.0)
  • Quality: scores within 1 point (avg 7.5/10, range 7.0-8.0)
  • Testing: scores within 1 point (avg 6.5/10, range 6.0-7.0)
  • Risks: scores within 1 point (avg 7.0/10, range 7.0-7.0)

Disagreement

Dimension openai anthropic
Verdict CONCERNS PASS

Unique Insights

  • openai: The new dispatch-acceptance polling path is executed under bash -e without guarding gh run list | jq. A transient GitHub CLI/API failure or jq failure during any poll exits the step immediately, before the failed agents:format lease is removed. This leaves the issue unable to retry, which is the recovery condition this change is intended to address.; Acceptance detection uses a timestamp with second-level precision plus a display-title substring match. An unrelated or prior matching run created within the same second could be treated as confirmation that the failed dispatch was accepted, preserving the lease unnecessarily. This is a relatively low-probability false-positive but affects recovery behavior.
  • anthropic: The retry/polling logic for detecting an 'ambiguous' dispatch (gh workflow run CLI failure but run actually accepted) adds complexity (5 retries x 2s sleep, jq-based JSON matching on createdAt/displayTitle) that is harder to verify deterministically in tests; correctness relies on GitHub API timing assumptions (string-based ISO8601 comparison, title matching '#NUMBER').; The diff for tests/workflows/test_agents_issue_optimizer_format_trigger.py only shows +10 lines with no visibility into what new scenario is covered (e.g., dispatch-failure-then-lease-release path is not obviously exercised based on the truncated diff).; No new/updated test asserting the info-level logging fix (console.log vs console.error) is visible in the diff for github-api-with-retry.test.js, though existing CI (JavaScript Tests) reportedly passed.; Manual verification of git diff --check and the two pytest/node test commands listed in acceptance criteria isn't directly confirmable from the diff alone, though CI summary indicates related test suites passed.

🔍 LangSmith Traces

@stranske

stranske commented Aug 9, 2026

Copy link
Copy Markdown
Owner Author

Closer verifier disposition (split report)

Provider report on merged PR #2985 (comment 5229813293): openai CONCERNS (84%) / anthropic PASS (72%).

Audited against current main:

  1. Stated tasks present — Failed-dispatch lease release after acceptance probe, advisory issue-dedup under set +e, info-level logging fallback, and consumer template mirror are on main (anthropic PASS aligns).
  2. openai residual is real — In .github/workflows/agents-issue-format-guard.yml (~L311–342) the gh run list | jq acceptance poll still runs under the surrounding set -euo pipefail without a set +e / || true guard. A transient CLI/jq failure can exit before --remove-label agents:format. Same pattern in the consumer template copy.
  3. No open source issue — Standalone sync/source PR with empty closingIssuesReferences. Residual is a bounded shell hardening follow-up, not a completeness miss of fix(agents): preserve format guard recovery #2985's stated tasks.

Disposition: accept anthropic PASS for stated scope; record openai residual as known hardening debt (unguarded acceptance poll). Closer will address in a bounded follow-up or same-round complex fix if capacity remains after open PR drain. No issue to close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent:codex Agent-created issues from Codex agent:needs-attention Agent needs human review or intervention agents:keepalive Use to initiate keepalive functionality with agents autofix:patch autofix Opt-in automated formatting & lint remediation needs-human Requires human intervention or review verify:compare Compare multiple LLM evaluations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants